package com.xunk.scene.enums;

import com.xunk.common.core.interfaces.EnumValidateInterface;
import lombok.Getter;

/**
 * @ProjectName: HIM
 * @Package: com.xunk.scene.enums
 * @ClassName: FlagOneZeroEnum
 * @Author: luanzhiwei
 * @Description: 标识0和1的枚举
 * @Date: 2021/5/19 14:51
 * @Version: 1.0
 */
@Getter
public enum FlagOneZeroEnum implements EnumValidateInterface {

    STRING_ZERO("0", "关闭,失效,自动"),
    STRING_ONE("1", "开启,生效,手动");

    private String code;
    private String desc;

    FlagOneZeroEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据code获取枚举
     *
     * @param code
     * @return
     */
    public static FlagOneZeroEnum getByCode(String code) {
        for (FlagOneZeroEnum value : FlagOneZeroEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 判断是否是可用枚举
     *
     * @param code
     * @return
     */
    @Override
    public Boolean isValidEnum(String code) {
        for (FlagOneZeroEnum value : FlagOneZeroEnum.values()) {
            if (value.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }
}
